package com.allwees.bs.core.modelbase.constant;

import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 * error message 映射, 用于 i18n 获取字段属性, 再转成 message
 *
 * @author: Xiao Xuezhi
 * @email: index.xiao@foxmail.com
 * @date: 2020/12/4 18:02
 * @since: 1.0.0
 */
@Slf4j
public final class ErrorMessageMap {

    private static Map<String, String> map = new HashMap<>(256);

    static {
        Field[] declaredFields = ErrorMessage.class.getFields();
        for (Field field : declaredFields) {
            try {
                map.put(String.valueOf(field.get(ErrorMessage.class)), field.getName());
            } catch (Exception e) {
                log.error(e.getMessage(), e);
            }
        }
    }

    public static String get(String msg) {
        return map.get(msg);
    }

}
